using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using MobileClient.UIProcessService;

namespace MobileClient
{
	/// <summary>
	/// Summary description for ctlDateEntryNA.
	/// </summary>
	public class ctlDateEntryNA : Control
	{
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.TabControl tabControl;
		private System.Windows.Forms.TabPage tabDate;
		private System.Windows.Forms.TabPage tabNA;
		private System.Windows.Forms.CheckBox chkNA;
		private DateTimePicker datePicker;
		private int m_nSelected = 0;

		private DateEntryNA m_objEntry;

		public ctlDateEntryNA()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();

			m_objEntry = null;
		}

		public DateEntryNA Entry
		{
			get { return m_objEntry; }
			set { m_objEntry = value; }
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if( components != null )
					components.Dispose();
			}
			base.Dispose( disposing );
		}

		#region Component Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.tabControl = new System.Windows.Forms.TabControl();
			this.tabDate = new System.Windows.Forms.TabPage();
			this.datePicker = new DateTimePicker();
			this.tabNA = new System.Windows.Forms.TabPage();
			this.chkNA = new System.Windows.Forms.CheckBox();
			// 
			// tabControl
			// 
			this.tabControl.Controls.Add(this.tabDate);
			this.tabControl.Controls.Add(this.tabNA);
			this.tabControl.Location = new System.Drawing.Point(3, 6);
			this.tabControl.SelectedIndex = 0;
			this.tabControl.Size = new System.Drawing.Size(230, 140);
			this.tabControl.SelectedIndexChanged +=new EventHandler(tabControl_SelectedIndexChanged);
			// 
			// tabDate
			// 
			this.tabDate.Controls.Add(this.datePicker);
			this.tabDate.Location = new System.Drawing.Point(4, 22);
			this.tabDate.Size = new System.Drawing.Size(222, 114);
			this.tabDate.Text = "Date";
			// 
			// datePicker
			// 
			this.datePicker.Format = DateTimePickerFormat.Long;
			this.datePicker.Location = new System.Drawing.Point(11, 47);
			this.datePicker.Size = new System.Drawing.Size(212, 20);
			// 
			// tabNA
			// 
			this.tabNA.Controls.Add(this.chkNA);
			this.tabNA.Location = new System.Drawing.Point(4, 22);
			this.tabNA.Size = new System.Drawing.Size(222, 114);
			this.tabNA.Text = "N/A";
			// 
			// chkNA
			// 
			this.chkNA.Location = new System.Drawing.Point(63, 45);
			this.chkNA.Size = new System.Drawing.Size(96, 24);
			this.chkNA.Text = "Not Applicable";
			// 
			// ctlDateEntryNA
			// 
			this.Controls.Add(this.tabControl);
			this.Size = new System.Drawing.Size(236, 152);
		}
		#endregion

		public void LoadSettings()
		{
			tabControl.SelectedIndex = 0;

			if(m_objEntry != null)
			{
                if (String.IsNullOrEmpty(m_objEntry.Date))
                {
                    datePicker.Value = DateTime.Today;
                }
                else
                {
                    datePicker.Value = Convert.ToDateTime(m_objEntry.Date);
                }
                chkNA.Checked = m_objEntry.NotApplicable;
			}
		}

		public void SaveSettings()
		{
			if(m_objEntry != null)
			{
				m_objEntry.Date = datePicker.Value.ToShortDateString();
				m_objEntry.NotApplicable = chkNA.Checked;
			}
		}

		private void tabControl_SelectedIndexChanged(object sender, EventArgs e)
		{
			int nIndex = tabControl.SelectedIndex;
			tabControl.TabPages[m_nSelected].Visible = false;			
			tabControl.TabPages[nIndex].Visible = true;
			m_nSelected = nIndex;
		}
	}
}
